import sys
import traceback

import Ice

from examples import Demo


class PrinterImpl(Demo.Printer):
    def printString(self, s, current=None):
        print(s, "conn->", current.con.toString(), " id->", current.id, " facet->", current.facet, " operation->",
              current.operation)
        print(current.con.getInfo().adapterName)
        print(current.con.getACM())


if __name__ == '__main__':

    status = 0
    ic = None
    try:
        ic = Ice.initialize(sys.argv)
        adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000")
        obj = PrinterImpl()
        adapter.add(obj, ic.stringToIdentity("SimplePrinter"))
        adapter.activate()
        ic.waitForShutdown()
    except:
        traceback.print_exc()
        status = 1

    if ic:
        # Clean up
        try:
            ic.destroy()
        except:
            traceback.print_exc()
            status = 1

    sys.exit(status)
